<?php
class CTemplator extends SmartyBC
{
	protected $data;
	
	public function __construct($config=null) 
    { 
      parent::__construct();
	  $this->data=$config; 
    } 
	
	public function init()
	{	 
		$this->debugging = false;
		$this->caching = false;
		$this->cache_lifetime = 120;
		$this->setCacheDir($this->getObject('CurrentRoute:Cache').DIRECTORY_SEPARATOR.
					$this->getObject('CurrentRoute:ModuleId').'/');
		$this->setCompileDir($this->getObject('CurrentRoute:Runtime').DIRECTORY_SEPARATOR.
					$this->getObject('CurrentRoute:ModuleId').'/');
		$this->setTemplateDir(
				$this->getObject('CurrentRoute:Layout').
				DIRECTORY_SEPARATOR.
				$this->getObject('CurrentRoute:Theme').
				DIRECTORY_SEPARATOR
				);
		 $this->assign('assets',
				$this->getObject('CurrentRequest:Request:BaseUrl').
				'/'.
				$this->getObject('CurrentRoute:Assets').
				'/'.
				$this->getObject('CurrentRoute:Theme').
				'/'
			);
		$this->assign('upload',
				$this->getObject('CurrentRequest:Request:BaseUrl').
				'/'.
				$this->getObject('CurrentRoute:site').
				'/'.
				'upload'.
				'/'
			);		
	}
	
	public function addViewsDir($dirpath)
	{
		if(is_string($dirpath))
		$this->addTemplateDir($dirpath);
	}
	public function getObject($obj)
	{
		$objects = explode(":",$obj);
		$object=$this->data->itemAt($objects[0]);
		for ($i=1; $i<count($objects); $i++)
		{
			$method='get'.$objects[$i];
			if(isset($object))
			$object=$object->$method();
			else
			 $object=null;
		 
		}
	 return $object;
	}
}

